Skip to main content
Version: 1.0.0

processSupportRequest

Admin NotificationUser Confirmation
Admin Support Request TemplateUser Support Request Confirmation Template

Function Name: processSupportRequest

Author: Domenico Cerone Creation Date: 25/09/2025
Last Reviewer: Domenico Cerone

Trigger: HTTPS (onRequest)

Purpose: Manages the processing and sending of email notifications for user support requests through a dual notification system. When a support request is received, it automatically sends a notification to administrators with all details and attachments, and a confirmation email to the user who created the request.

Detailed Functionalityโ€‹

This module handles the complete processing of support requests through a dual notification system:

1. TRIGGER AND INPUTโ€‹

  • Receives HTTP POST requests with 'supportRequestId' parameter
  • Example: { "supportRequestId": "tMulEHxpGe4q0Sc9zmaf" }
  • Input validation and HTTP method checking

2. SUPPORT REQUEST DATA RETRIEVALโ€‹

  • Accesses Firestore 'SupportRequests' collection
  • Retrieves document using the provided ID parameter
  • Extracts: email, supportType, title, description, createdAt, images[]
  • Error handling if document doesn't exist

3. ADMINISTRATOR IDENTIFICATIONโ€‹

  • Query on 'Profiles' collection with filter: role == 'Admin'
  • Collects array of administrator recipient emails
  • Fallback error if no admin found in the system

4. REQUESTING USER PROFILE RETRIEVALโ€‹

  • Uses email from support request as document ID in 'Profiles'
  • Extracts firstName and lastName for full name
  • Fallback logic: if name not available, uses email
  • Result: "Michele Telesca" or "92mt@live.it"

5. NOTIFICATION PREFERENCE CHECKโ€‹

  • Checks if the user has enabled the processSupportRequest notification in their notification preferences
  • Verifies notification_types.processSupportRequest field in the profile
  • If notification is disabled (false): returns success without sending email
  • If notification is enabled (true): proceeds with administrator identification
  • Provides clear logging about notification preference status

6. ATTACHMENT DOWNLOAD AND PREPARATIONโ€‹

  • Iterates 'images' array from support request
  • For each image: download from Firebase Storage URL
  • Conversion to base64 format for email attachment
  • Automatic MIME type detection from file extension
  • 30-second timeout to avoid network blocks
  • Error handling for failed downloads

7. DUAL EMAIL SYSTEMโ€‹

A) ADMINISTRATOR EMAILโ€‹

  • Template: 13ef.8598f19fbcc5adb.k1.d36f1920-618a-11f0-ae4f-dad70ff08860.1980e8f5bb2
  • Recipients: ALL users with role='Admin'
  • Attachments: All support request images
  • Merge data:
    • profile: user full name ("Michele Telesca")
    • createdAt: Italian formatted date ("15/07/2025, 14:51:22")
    • supportType: request type ("bug_report")
    • title: request title ("Bug assurdo nella frame!")
    • description: complete problem description

B) USER CONFIRMATION EMAILโ€‹

  • Template: 13ef.8598f19fbcc5adb.k1.94036240-6190-11f0-ae4f-dad70ff08860.1980eb50e64
  • Recipient: Email of user who created the request
  • Content: Simple message "Hello, Your support request has been sent..."
  • Attachments: None (confirmation only)
  • Merge data: None (static template)

8. RESPONSE AND LOGGINGโ€‹

  • Detailed logging of each phase for debugging
  • JSON response with complete results of both sends
  • Counts: admin emails, attachments, send status
  • Error handling with specific messages

Technical Featuresโ€‹

  • PROTOCOL: Firebase Cloud Functions v2 with HTTP trigger
  • DATABASE: Firestore with 'SupportRequests' and 'Profiles' collections
  • EMAIL: ZeptoMail API with custom templates
  • STORAGE: Firebase Storage for image downloads
  • ATTACHMENTS: Base64 conversion with automatic MIME detection
  • TIMEOUT: 30 seconds for image downloads
  • FALLBACK: Nodemailer available but not used
  • LOGGING: Complete for monitoring and debugging

Error Handlingโ€‹

  • Non-POST method โ†’ 405 Method Not Allowed
  • Missing ID โ†’ 400 Bad Request
  • Support request not found โ†’ 404 Not Found
  • No admin found โ†’ 404 Not Found
  • ZeptoMail errors โ†’ 500 Internal Server Error
  • Image download failed โ†’ Continue without attachment
  • User profile not found โ†’ Use email as fallback

Input (Payload):โ€‹

{
"supportRequestId": "tMulEHxpGe4q0Sc9zmaf"
}

Parameters:

  • supportRequestId (string, required): ID of the document in the 'SupportRequests' collection containing support request details

Output (Success):โ€‹

{
"success": true,
"message": "Email di notifica inviata agli amministratori e email di conferma inviata all'utente",
"adminEmails": ["admin1@arshades.com", "admin2@arshades.com"],
"userEmail": "92mt@live.it",
"attachmentCount": 1,
"adminResponse": { ... },
"userResponse": { ... }
}

Response Properties:

  • success (boolean): Indicates if the operation was completed successfully
  • message (string): Descriptive message of the result
  • adminEmails (array): List of administrator emails that received the notification
  • userEmail (string): Email of the user who received the confirmation
  • attachmentCount (number): Number of attachments processed and sent
  • adminResponse (object): Complete response from admin email sending
  • userResponse (object): Complete response from user confirmation email sending

This output is returned in the HTTP response (Postman, browser, curl).

Testingโ€‹

URL (if HTTPS): http://127.0.0.1:5001/arshadesstaging/us-central1/processSupportRequest

Test with Emulator:

  1. Start the Firebase emulator: firebase emulators:start --only functions
  2. Ensure you're using Node.js version 20: nvm use 20
  3. Test with curl:
curl -X POST "http://127.0.0.1:5001/arshadesstaging/us-central1/processSupportRequest" \
-H "Content-Type: application/json" \
-d '{"supportRequestId": "tMulEHxpGe4q0Sc9zmaf"}'

Postman Testing:

Deploy Command:โ€‹

firebase deploy --only functions:processSupportRequest

Production URL:โ€‹

processSupportRequest: https://us-central1-arshades-7e18a.cloudfunctions.net/processSupportRequest